#include "piece.h"

struct PiecePos{
    int row, col;
    Piece::TYPE type;
};

Piece::Piece()
{

}

void Piece::init(int id) {
    PiecePos pos[16] = {
                 {1, 1, Piece::CHE},
                 {1, 2, Piece::MA},
                 {1, 3, Piece::XIANG},
                 {1, 4, Piece::SHI},
                 {1, 5, Piece::KING},
                 {1, 6, Piece::SHI},
                 {1, 7, Piece::XIANG},
                 {1, 8, Piece::MA},
                 {1, 9, Piece::CHE},
                 {3, 2, Piece::PAO},
                 {3, 8, Piece::PAO},
                 {4, 1, Piece::BING},
                 {4, 3, Piece::BING},
                 {4, 5, Piece::BING},
                 {4, 7, Piece::BING},
                 {4, 9, Piece::BING},
                 };

    this->id = id;
    isAlive = true;
    red = id < 16;

    if(id < 16) {
        this->row = pos[id].row;
        this->col = pos[id].col;
        this->type = pos[id].type;
    } else {
        this->row = 11-pos[id-16].row; //行对称：1+10=2+8……
        this->col = 10-pos[id-16].col; //列对称：1+9=2+7……
        this->type = pos[id-16].type;
    }

}

QString Piece::getText() {
    switch(this->type) {
    case KING:
        if (red)
            return "帅";
        else
            return "将";
    case CHE:
        return "车";
    case MA:
        return "马";
    case PAO:
        return "炮";
    case XIANG:
        if (red)
            return "相";
        else if (!red)
            return "象";
    case SHI:
        if (red)
            return "仕";
        else
            return "士";
    case BING:
        if (red)
            return "兵";
        else if (!red)
            return "卒";
    }
}
